import {
  isWhatType
} from '../utils/utilsNew';

export const parseAreaFilter = function (data) {
  let area = ''
  try {
    area = data[0][1] && data[0][1] !== "INFINTE" ? data[0][1] : '';
  } catch (error) {
    area = ''
  }
  return area
}

export const parseDistrictFilter = function (data) {
  let bizCircleIds = [];
  try {
    (data || []).forEach((item) => {
      if (item[2] && item[2] !== "INFINTE") {
        bizCircleIds.push(item[2]);
      }
    });
  } catch (error) {}
  return bizCircleIds
}

export const formatDistrictOptions = function (options) {
  if (!(options && options.length)) {
    return [];
  }
  let list = options.map((item) => {
    const list = {
      value: item.areaCode,
      label: item.areaName,
    };
    if (item.hdBizcircleList) {
      list.children = item.hdBizcircleList.map((itx) => {
        return {
          value: itx.id,
          label: itx.bizcircleName,
        };
      });
    } else {
      list.children = [];
    }
    list.children.unshift({
      value: "INFINTE",
      label: "不限",
    });
    return list;
  });
  list.unshift({
    value: "INFINTE",
    label: "不限",
  });
  return [{
    value: "area",
    label: "区域",
    children: list,
  }];
}

export const parseFilter = function (data) {
  let newData = {}
  Object.keys(data).forEach(item => {
    switch (isWhatType(data[item])) {
      case 'String':
        newData[item] = data[item] ? data[item] : ''
        break
      case 'Object':
        newData[item] = [{
          min: Number(data[item].min) || null,
          max: Number(data[item].max) || null
        }]
        break
      case 'Array':
        newData[item] = data[item].map(_item => {
          if (_item.indexOf(',') !== -1) {
            let value = _item.split(',')
            return {
              min: value[0] ? Number(value[0]) : null,
              max: value[1] ? Number(value[1]) : null,
            }
          } else {
            return _item
          }
        })
        break
    }
  })
  return newData
}

export const parseFilterx = function (data) {
  let newData = {}
  Object.keys(data).forEach(item => {
    switch (isWhatType(data[item])) {
      case 'String':
        newData[item] = data[item] ? data[item] : ''
        break
      case 'Object':
        newData[item] = [{
          min: Number(data[item].min*10000) || null,
          max: Number(data[item].max*10000) || null
        }]
        break
      case 'Array':
        newData[item] = data[item].map(_item => {
          if (_item.indexOf(',') !== -1) {
            let value = _item.split(',')
            return {
              min: value[0] ? Number(value[0]) : null,
              max: value[1] ? Number(value[1]) : null,
            }
          } else {
            return _item
          }
        })
        break
    }
  })
  return newData
}

export const rangeHouseType = [{
  label: '一室',
  value: '1'
}, {
  label: '二室',
  value: '2'
}, {
  label: '三室',
  value: '3'
}, {
  label: '四室',
  value: '4'
}, {
  label: '五室',
  value: '5'
}, {
  label: '五室及以上',
  value: '6'
}]

export const rangeArea = [{
    label: '60㎡及以下',
    value: '0,60',
  },
  {
    label: '60-90㎡',
    value: '60,90',
  },
  {
    label: '90-120㎡',
    value: '90,120',
  },
  {
    label: '120-150㎡',
    value: '120,150',
  },
  {
    label: '150-180㎡',
    value: '150,180',
  },
  {
    label: '180-240㎡',
    value: '180,240',
  },
  {
    label: '240-320㎡',
    value: '240,320',
  },
  {
    label: '320-600㎡',
    value: '320,600',
  },
  {
    label: '600㎡及以上',
    value: '600,',
  }
];

export const rangeSalesPrice = [{
    label: '200万及以下',
    value: '0,2000000'
  },
  {
    label: '200-300万',
    value: '2000000,3000000'
  },
  {
    label: '300-400万',
    value: '3000000,4000000'
  },
  {
    label: '400-500万',
    value: '4000000,5000000'
  },
  {
    label: '500-800万',
    value: '5000000,8000000'
  },
  {
    label: '800-1000万',
    value: '8000000,10000000'
  },
  {
    label: '1000-1500万',
    value: '10000000,15000000'
  },
  {
    label: '1500-2000万',
    value: '15000000,20000000'
  },
  {
    label: '2000万及以上',
    value: '20000000,'
  }
];


export const rangeRentPrice = [{
  label: '1000元及以下',
  value: '0,1000'
}, {
  label: '1000-1500元',
  value: '1000,1500'
}, {
  label: '1500-2000元',
  value: '1500,2000'
}, {
  label: '2000-3000元',
  value: '2000,3000'
}, {
  label: '3000-5000元',
  value: '3000,5000'
}, {
  label: '5000-8000元',
  value: '5000,8000'
}, {
  label: '8000-12000元',
  value: '8000,12000'
}, {
  label: '12000元及以上',
  value: '12000,'
}]

// function getLable(conf, unit) {
//   if (!conf.max) return conf.min + unit + '以上'
//   if (!conf.min) return conf.max + unit + '以下'
//   return `${conf.min}-${conf.max}${unit}`
// }

// /** 面积过滤 */
// export const rangeArea = _rangeArea.map((item) => {
//   return {
//     label: getLable(item, '㎡'),
//     value: item,
//   }
// });

// /** 二手价格 */
// export const rangeSalesPrice = _rangeSalesPrice.map((item) => {
//   return {
//     label: getLable(item, '万'),
//     value: Object.keys(item).reduce((res, key) => {
//       res[key] = item[key] * 10000
//       return res
//     }, {}),
//   }
// });

// /** 出租价格滤 */
// export const rangeRentPrice = _rangeRentPrice.map((item) => {
//   return {
//     label: getLable(item, '元'),
//     value: item,
//   }
// });

// 房源亮点
export const lightSpotType = [{
    label: "独家房源",
    value: "独家房源"
  },
  {
    label: "有钥匙",
    value: "有钥匙"
  },
  {
    label: "付佣金",
    value: "付佣金"
  },
];

// 服务年限
export const serviceLife = [{
  label: "满五",
  value: "满五"
}, {
  label: "满二",
  value: "满二"
}, {
  label: "不满二",
  value: "不满二"
}]

// 楼层
export const floor = [{
  label: "高楼层",
  value: "高楼层"
}, {
  label: "中楼层",
  value: "中楼层"
}, {
  label: "低楼层",
  value: "低楼层"
}]

// 装修
export const decoration = [{
  label: "毛坯",
  value: "毛坯"
}, {
  label: "简装",
  value: "简装"
}, {
  label: "精装",
  value: "精装"
}, {
  label: "豪装",
  value: "豪装"
}]

// 朝向
export const orientation = [{
  label: "东",
  value: "东"
}, {
  label: "南",
  value: "南"
}, {
  label: "西",
  value: "西"
}, {
  label: "北",
  value: "北"
}, {
  label: "东北",
  value: "东北"
}, {
  label: "东南",
  value: "东南"
}, {
  label: "西北",
  value: "西北"
}, {
  label: "西南",
  value: "西南"
}, {
  label: "南北",
  value: "南北"
}, {
  label: "东西",
  value: "东西"
}]

// 户型 室
export const room = [{
  label: "1室",
  value: "1"
}, {
  label: "2室",
  value: "2"
}, {
  label: "3室",
  value: "3"
}]

// 户型 厅
export const hall = [{
  label: "0厅",
  value: "0"
}, {
  label: "1厅",
  value: "1"
}, {
  label: "2厅",
  value: "2"
}]

// 户型 卫
export const toilet = [{
  label: "0卫",
  value: "0"
}, {
  label: "1卫",
  value: "1"
}, {
  label: "2卫",
  value: "2"
}]


// 是否唯一
export const notTheOnly = [{
  label: "唯一",
  value: 1,
}, {
  label: "不唯一",
  value: 2,
}]

// 是否唯一
export const rangeType = [{
  label: '二手',
  value: 'SALES'
}, {
  label: '出租',
  value: 'RENT'
}]